#include "cgi.cpp"
#include <cctype>
#include <algorithm>
#define TOSTRING(i) #i
using namespace cppcgi;
using namespace std;

char easytolower(char in)
{
    if (in<='Z' && in>='A')
        return in-('Z'-'z');
    return in;
}

KvMap AXBCombination(kvmap a, kvmap b)
{
    KvMap c;
    for (kvmap::iterator it1 = a.begin(); it1 != a.end(); it1++)
    {
        for (kvmap::iterator it2 = b.begin(); it2 != b.end(); it2++)
            c.Insert(it1->first + it2->first, it2->first + it1->first);
    }
    return c;
}

KvMap FileCombination(string file1, string file2)
{
    ifstream ofs1(file1.c_str());
    string line;
    KvMap a;
    KvMap b;
    while (getline(ofs1, line))
    {
        //cout << line << endl;
        a.Insert(line, line);
    }

    ifstream ofs2(file2.c_str());
    while (getline(ofs2, line))
    {
        //cout << line << endl;
        b.Insert(line, line);
    }

    return AXBCombination(a.Dump(), b.Dump());
}

int main()
{
#if 0
    string s = "00:34:45";
    cppcgi::KvVector a = cppcgi::Split(s, ":");
    cppcgi::Test::Alert(a);
    // 字符串里面是可以包含换行字符的，但不能包含\0
    string ss = "aaaaaa\r\nbbbbb\0ccccc\ndddddd";
    cout << ss.size() << endl;
    cout << ss << endl;
#else
    ifstream ofs("1位字母.txt");
    if (!ofs)
    {
        return 0;
    }
    File* ifile = File::Open("3位字母.txt", "w");
    KvMap tmp = FileCombination("1位字母.txt", "2位字母.txt");
    string line;
    while (getline(ofs, line))
    {
        string s = line;
        //transform(s.begin(),s.end(),s.begin(),easytolower);
        //Trim(s);
        //tmp.Insert(s,s);
    }
    kvmap tmpmap = tmp.Dump();
    for (kvmap::iterator it = tmpmap.begin(); it != tmpmap.end(); it++)
    {
        ifile->AddLine(it->first);
    }


#endif // 0

    return 0;
}
